package cn.edu.gzmtu.dao;

import cn.edu.gzmtu.domain.Product;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 产品信息dao层
 */
@Repository("productDao")
public interface IProductDao {

    /**
     * 查询所有的产品信息
     *
     * @return
     * @throws Exception
     */
    @Select("SELECT * from product")
    List<Product> findAll() throws Exception;

    /**
     * 根据id查询产品信息
     * @param id
     * @return
     * @throws Exception
     */
    @Select("SELECT * from product WHERE id=#{id}")
    Product findById(String id) throws Exception;

    /**
     * 添加产品
     * @param product
     */
    @Insert("insert into PRODUCT (productnum, productname, cityname, departuretime, productprice,productdesc, productstatus) " +
            "values (#{productNum}, #{productName}, #{cityName}, #{departureTime}, #{productPrice}, #{productDesc}, #{productStatus})")
    void save(Product product);
}
